package com.own.weihao;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = null;
        try {
            scanner = new Scanner(new File("输入文件.txt"));
        } catch (FileNotFoundException e) {
            System.out.println("找不到<输入文件.txt>文件");
            e.printStackTrace();
        }

        File outDir = new File("输出目录");
        outDir.mkdir();

        PrintWriter printWriter = null;
        try {
            printWriter = new PrintWriter(new File("./输出目录/"+new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒").format(new Date()) +".txt"));
        } catch (FileNotFoundException e) {
            System.out.println("无法生成输出文件");
            e.printStackTrace();
        }
        while(scanner.hasNext()) {
            String string = scanner.next();
            JSONObject jsonObject = (JSONObject) JSON.parse(string);
            List<Map<String,String>> list = (List<Map<String, String>>) jsonObject.get("dlink");
            for(Map<String,String> map : list) {
                String url = map.get("dlink").toString().replace("\\","");
                printWriter.println(url);
                try {
                    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        printWriter.close();
        System.out.println("下载链接已成功输出");
    }
}
